package com.devops.utils;

import com.devops.entity.resp.ErrorReason;
import com.devops.entity.resp.ResponseResult;

import java.util.List;

/**
 * 响应工具类
 */
public class ResponseUtils<T> {

    private static final String SUCCESS = "success";
    private static final String ERROR = "error";

    private static final String SUCCESS_STATUS = "200";
    private static final String ERROR_STATUS = "0";
    private static final String NOT_FOUND_STATUS = "404";

    public static <T> ResponseResult<T> success (T data) {
        return success(SUCCESS, data);
    }

    public static <T> ResponseResult<T> success (String msg, T data) {
        ResponseResult response = new ResponseResult();
        response.setData(data);
        response.setCode(SUCCESS_STATUS);
        response.setMsg(msg);
        return response;
    }

    public static <T> ResponseResult<T> error(List<ErrorReason> errorReasonList) {
        ResponseResult response = new ResponseResult();
        response.setCode(ERROR_STATUS);
        response.setMsg(ERROR);
        response.setErrorList(errorReasonList);
        return response;
    }

}
